/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mathma.core.vector;

import mathma.core.expr.Expression;

import mathma.core.form.MultiExpression;

import mathma.core.value.Value;

import java.util.List;

/**
 * @since 0.2.6
 * @author Ethan Levine
 */
public class VectorAdditionExpression<E extends Value>
        extends MultiExpression<Vector<E>, Vector<E>> {

    public VectorAdditionExpression(Expression<Vector<E>>... vectors) {
        super(Vector.GenericType, vectors);
    }

    public VectorAdditionExpression(List<Expression<Vector<E>>> vectors) {
        super(Vector.GenericType, vectors);
    }
    
    public Vector<E> evaluate() {
        Vector<E> sum = null;
        for (Expression<Vector<E>> vector : this) {
            if (sum == null) {
                sum = vector.evaluate();
            } else {
                sum = sum.add(vector.evaluate());
            }
        }
        return sum;
    }

    public VectorAdditionExpression<E> newInstance(List<Expression<Vector<E>>> operands) {
        return new VectorAdditionExpression<E>(operands);
    }
}
